# -*- coding: utf-8 -*-
import json


#测试库企业证书计数
def getPersonAptCount(request):

    list1 = []
    request.cursor_33.execute('''
        select
            lx_id,
            ifnull(qualifi_type,'') qualifi_type,
            ifnull(qualifi_name,'') qualifi_name,
            ifnull(qualifi_major,'') qualifi_major,
            count(*) as total
        from yibiao.yb_biz_person_aptitude
        group by lx_id,ifnull(qualifi_type,''),ifnull(qualifi_name,''),ifnull(qualifi_major,'')
        order by ifnull(qualifi_type,''),ifnull(qualifi_name,''),ifnull(qualifi_major,'')
    ''')
    rows = request.cursor_33.fetchall()
    already_lx_id_list = set()
    for row in rows:
        already_lx_id_list.add(row['lx_id'])
        list1.append(row)

    all_id_set = set()
    #从中间库取出全部人员资质id集合
    request.cursor_standard.execute('''
        select distinct cert_dict_id from standard.dict_person_apt
    ''')
    for row in request.cursor_standard.fetchall():
        all_id_set.add(row['cert_dict_id'])



    for id in all_id_set:
        if id not in already_lx_id_list:
            request.cursor_standard.execute('''
                select  cert_dict_id as lx_id,qualifi_type,qualifi_name,qualifi_major  from standard.dict_person_apt where cert_dict_id = {}
            '''.format(id))
            one_dict = request.cursor_standard.fetchone()
            list1.insert(1,one_dict)


    return json.dumps(list1, ensure_ascii=False)



def getZeroPersonAPtCount(request):

    #1，先从测试库拿到所有人员证书类型
    lx_id_set = set()
    request.cursor_33.execute('''
        select 
            distinct lx_id
        from yibiao.yb_biz_person_aptitude
    ''')
    for row in request.cursor_33.fetchall():
        lx_id_set.add(row['lx_id'])

    #

